#coding: utf-8
class CulturalHeritage::PreRegisterRequest < ActiveRecord::Base
  default_scope where("deleted = 0")
   has_many :cultural_heritage_pre_registers, :class_name => 'CulturalHeritage::CulturalHeritagePreRegister',  :foreign_key => 'cultural_heritage_pre_registers'
   has_many :list_parts, :class_name => 'CulturalHeritage::Part',  :foreign_key => 'cultural_heritage'
  has_many :list_cultural_heritages, :class_name => 'CulturalHeritage::CulturalHeritage',  :foreign_key => 'foundInId'
  has_many :list_avatars, :class_name => 'CulturalHeritage::CulturalHeritageAvatar',  :foreign_key => 'cultural_heritage'
  has_many :list_researches, :class_name => 'CulturalHeritage::CulturalHeritageFile',  :foreign_key => 'cultural_heritage'
  has_many :list_videos, :class_name => 'CulturalHeritage::CulturalHeritageYoutube',  :foreign_key => 'cultural_heritage'
  belongs_to :obj_collection, :class_name => 'CulturalHeritage::Collection',  :foreign_key => 'collection'
#  belongs_to :obj_state, :class_name => 'CulturalHeritage::State',  :foreign_key => 'state'
  belongs_to :obj_group, :class_name => 'CulturalHeritage::Group',  :foreign_key => 'group'
  belongs_to :obj_subGroup, :class_name => 'CulturalHeritage::SubGroup',  :foreign_key => 'subGroup'
  belongs_to :obj_tipology, :class_name => 'CulturalHeritage::Tipology',  :foreign_key => 'tipology'
  #Revisar el caso de que sea mueble y esté en un inmueble o en una institucion cultural, implica polimorfismo
  #belongs_to :obj_located_at_cultural_heritage, :class_name => 'CulturalHeritage::CulturalHeritage',  :foreign_key => 'cultural_heritage'
  belongs_to :obj_period, :class_name => 'CulturalHeritage::Period',  :foreign_key => 'period'
  belongs_to :obj_culture, :class_name => 'CulturalHeritage::Culture',  :foreign_key => 'culture'
  belongs_to :obj_style, :class_name => 'CulturalHeritage::Style',  :foreign_key => 'style'
  belongs_to :obj_owner, :class_name => 'Security::Person',  :foreign_key => 'owner'
  belongs_to :obj_author, :class_name => 'Security::Person',  :foreign_key => 'author'
  belongs_to :obj_conservational_state, :class_name => 'CulturalHeritage::ConservationalState',  :foreign_key => 'conservationalState'
  belongs_to :obj_integrity_state, :class_name => 'CulturalHeritage::IntegrityState',  :foreign_key => 'integrityState'
  belongs_to :obj_shape, :class_name => 'CulturalHeritage::Shape',  :foreign_key => 'shape'
  belongs_to :obj_technique, :class_name => 'CulturalHeritage::Technique',  :foreign_key => 'technique'
  belongs_to :obj_topic, :class_name => 'CulturalHeritage::Topic',  :foreign_key => 'topic'
  belongs_to :obj_typeCulturalInstitution, :class_name => 'CulturalHeritage::TypeCulturalInstitution',  :foreign_key => 'typeCulturalInstitution'
  belongs_to :obj_culturalInstitution, :class_name => 'CulturalHeritage::CulturalInstitution',  :foreign_key => 'culturalInstitution'
  belongs_to :obj_cultural_heritage, :class_name => 'CulturalHeritage::CulturalHeritage',  :foreign_key => 'culturalInstitution'
  belongs_to :obj_found_in_cultural_heritage, :class_name => 'CulturalHeritage::CulturalHeritage',  :foreign_key => 'foundInId'

   def str_state
    if state == 0
      return "Registrada"
    end
    if state == 1
      return "Aprobada"
    end
    if state == 2
      return "Rechazada"
    end



  end

   def self.list_states

  return  [["Registrada",0],["Aprobadas",1],["Rechazada",2]]
  end


      def str_owner
    if owner.blank?
      return ""
    else
      obj_person = Security::Person.find(owner)
      return obj_person.name
    end
  end

   def str_user
    if user.blank?
      return ""
    else
      obj_user = User.find(user)
      return obj_user.name
    end
  end

  def str_email
    if user.blank?
      return ""
    else
      obj_email = User.find(user)
      return obj_email.email
    end
  end

        def str_author
    if author.blank?
      return ""
    else
      obj_author = Security::Person.find(author)
      return obj_author.name
    end
  end

   def str_culture
    if culture.blank?
      return ""
    else
      obj_culture = CulturalHeritage::Culture.find(culture)
      return obj_culture.name
    end
  end

     def str_culturalInstitution
    if culturalInstitution.blank?
      return ""
    else
      obj_culturalInstitution = CulturalHeritage::CulturalInstitution.find(culturalInstitution)
      return obj_culturalInstitution.name
    end
  end

  def erasable
    cultuheri = CulturalHeritage::CulturalHeritage.count_pre_register_request_dependencies(id)
    if cultuheri >0
      return "Imposible borrar. Existen dependencias en patrimonio cultural/preregistro"    
    end
    return nil
  end

end
